package net.cz.wc.main;

import net.cz.wc.command.Command;
import net.cz.wc.command.CommandFactory;
import net.cz.wc.command.CommandTypeEnum;

public class MainXProject {
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		
		try {
			if (!validArgs(args)) {
				return;
			}
			
			Command theCommand = CommandFactory.createCommand(args[0]);
			
			theCommand.execute(args);
		} catch (Exception ee) {
			ee.printStackTrace();
		}
		
		System.out.println("Command executed in " + (System.currentTimeMillis() - start) + " ms");
	}
	
	private static boolean validArgs(String args[]) {
		
		if (args == null || args.length == 0) {
			System.out.println("Incomplete parameter number");
			System.out.println("Use xWC commands: ");
			System.out.println("java -jar xwc.jar <command>");
			System.out.println("where command must be one of the following: jrockit   hotspot   access   jmeter   ext");
			
			return false;
		}
		
		CommandTypeEnum command = CommandTypeEnum.getCommand(args[0]);
		
		if (command == null) {
			System.out.println("Incorrect parameter");			
			System.out.println("Use xProject commands: ");
			System.out.println("java -jar xproject.jar <command>");
			System.out.println("where command must be one of the following: jrockit   hotspot   access   jmeter   ext");
			
			return false;
		}
		
		return true;
	}
}
